#include <iostream>
#include "LocalSearch.h"
#include "InitialHalfGoodPopulation.h"
using namespace std;

void InitialHalfGoodPopulation::Create( std::vector<Solution> &output, int populationSize ){
	for( int i = 0 ; i < populationSize ; ++i ){
		vector<int> solution(_length , 0);
		bool *used = new bool [_length];
		fill( used, used+_length, false );

		for( int j = 0 ; j < _length ; ++j ){
			int randomNumber = rand() % _length;
			while( used[randomNumber] ){
				++randomNumber;
				randomNumber %= _length;
			}
			solution[j] = randomNumber;
			used[randomNumber] = true;
		}
		if( i > populationSize/2 )
			output.push_back( Solution(solution) );
		else
			output.push_back( _ls->Run(Solution(solution), 0.01) );
	}
}